<html>
<head>
  <title>Evernote Export</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="Evernote Windows/274061; Windows/6.1.7601 Service Pack 1;"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="381"/>

<div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><ol><li>把当前这目录变成git可以管理的仓库<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git init</code></pre></li><li>把文件添加到仓库<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git add filename</code></pre></li><li>git 仓库的状态<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git status</code></pre></li><li>把文件提交到仓库<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git commit -m &quot;wrote a readme file&quot;
[master (root-commit) cb926e7] wrote a readme file
 1 file changed, 2 insertions(+)
 create mode 100644 readme.txt</code></pre>
-m 后面是本次的提交说明</li><li>查看文件修改内容<br/><div><pre style="font-size: 13px; padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git diff readme.txt 
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distributed version control system.
 Git is free software.</code></pre></div>
查看工作区和版本库里面最新版本的区别(HEAD指向当前的分支)<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git diff HEAD -- readme.txt 
diff --git a/readme.txt b/readme.txt
index 76d770f..a9c5755 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,4 +1,4 @@
 Git is a distributed version control system.
 Git is free software distributed under the GPL.
 Git has a mutable index called stage.
-Git tracks changes.
+Git tracks changes of files.</code></pre></li><li>查看提交历史(只有commit)<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git log</code></pre><div><div>只显示版本号和提交注视<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git log --pretty=oneline
3628164fb26d48395383f8f31179f24e0882e1e0 append GPL
ea34578d5496d7dd233c827ed32a8cd576c5ee85 add distributed
cb926e7ea50ad11b8f9e909c05226233bf755030 wrote a readme file</code></pre></div>
查看命令历史(包含reset，commit等)<br/></div><div><pre style="font-size: 13px; padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git reflog</code></pre></div></li><li>在 git 中，当前版本用 HEAD 表示，上一个版本是 HEAD^ ,上上个版本是 HEAD^^，也可以用HEAD~+index，上10个版本可以写成 HEAD~10。</li><li>回到上一个版本<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git reset --hard HEAD^</code></pre>
根据版本号(<span style="color: inherit; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; line-height: 20px; white-space: pre-wrap;">3628164</span>)回到此版本<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git reset --hard 3628164</code></pre></li><li>查看工作区与版本库里面的文件区别<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git diff HEAD -- readme.txt 
diff --git a/readme.txt b/readme.txt
index 76d770f..a9c5755 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,4 +1,4 @@
 Git is a distributed version control system.
 Git is free software distributed under the GPL.
 Git has a mutable index called stage.
-Git tracks changes.
+Git tracks changes of files.</code></pre></li><li>把文件在工作区的修改全部撤销(git checkout -- file命令中的--很重要，没有--，就变成了“创建一个新分支”的命令)<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git checkout -- filename</code></pre>
如果文件修改后，还没有放到暂存区，撤销后，和版本的一样<br/>
如果文件已经放到暂存区，撤销户，回到暂存区的状态</li><li>把暂存区的文件撤销掉，重新放回工作区<br/><div><pre style="font-size: 13px; padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git reset HEAD readme.txt</code></pre></div>
请对照第8条git reset -- hard命令来进行区分</li><li>删除版本库里面的文件（包含再次 commit）
<pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><span style="color: inherit; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; line-height: 20px; white-space: pre-wrap;"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git rm test.txt
rm 'test.txt'
$ git commit -m &quot;remove test.txt&quot;
[master d17efd8] remove test.txt
 1 file changed, 1 deletion(-)
 delete mode 100644 test.txt</code></span></pre></li><li>生成 ssh key<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ ssh-keygen -t rsa -C &quot;youremail@example.com&quot;</code></pre>
一路默认（不要密码）<br/>
/Users/js/.ssh  里面保存了生成的 key .pub 是公钥</li><li>添加远程仓库<br/>
首先在 git 新建一个仓库（git init）,把这个仓库与本地仓库关联<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git remote add origin git@github.com:michaelliao/learngit.git</code></pre>
第一次把本地仓库的所有内容推送到远程库<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git push -u origin master</code></pre>
以后每次提交<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git push origin master</code></pre></li><li>SSH 警告（当你第一次使用Git的clone或者push命令连接GitHub时，会得到一个警告）<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?</code></pre>
这是因为Git使用SSH连接，而SSH连接在第一次验证GitHub服务器的Key时，需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器，输入yes回车即可<br/>
Git会输出一个警告，告诉你已经把GitHub的Key添加到本机的一个信任列表里了<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">Warning: Permanently added 'github.com' (RSA) to the list of known hosts.</code></pre>
这个警告只会出现一次，后面的操作就不会有任何警告了</li><li>从远程仓库克隆<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git clone git@github.com:pfjhetg/gitskills.git
Cloning into 'gitskills'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

$ cd gitskills
$ ls
README.md</code></pre></li><li>创建分支并且切换<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git checkout -b dev
Switched to a new branch 'dev'</code></pre>
-b 表示创建并且切换<br/>
等于下面两条命令<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git branch dev（创建）
$ git checkout dev（切换）
Switched to branch 'dev'</code></pre></li><li>查看当前分支<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git branch
* dev
  master</code></pre></li><li>合并指定分支（dev）到当前分支上<br/><div><pre style="font-size: 13px; padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git merge dev
Updating d17efd8..fec145a
Fast-forward
 readme.txt |    1 +
 1 file changed, 1 insertion(+)</code></pre></div>
注意到上面的Fast-forward信息，Git告诉我们，这次合并是“快进模式”，也就是直接把master指向dev的当前提交，所以合并速度非常快，这种模式下，删除分支后，会丢掉分支信息。如果要强制禁用Fast forward模式，Git就会在merge时生成一个新的commit，这样，从分支历史上就可以看出分支信息。加上--no-ff参数就可以用普通模式合并，合并后的历史有分支，能看出来曾经做过合并，而fast forward合并就看不出来曾经做过合并<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git merge --no-ff -m &quot;merge with no-ff&quot; dev
Merge made by the 'recursive' strategy.
 readme.txt |    1 +
 1 file changed, 1 insertion(+)</code></pre>
因为本次合并要创建一个新的commit，所以加上-m参数，把commit描述写进去</li><li>删除指定（feature1）分支 -d表示删除<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git branch -d feature1</code></pre></li><li>查看分支合并情况<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git log --graph --pretty=oneline --abbrev-commit
*   59bc1cb conflict fixed
|\
| * 75a857c AND simple
* | 400b400 &amp; simple
|/
* fec145a branch test
...</code></pre></li><li>bug 分支<br/>
当你接到一个修复一个代号101的bug的任务时，很自然地，你想创建一个分支issue-101来修复它，但是，等等，当前正在dev上进行的工作还没有提交：<br/>
将当前工作区储存起来，等恢复以后继续工作<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git stash
Saved working directory and index state WIP on dev: 6224937 add merge
HEAD is now at 6224937 add merge</code></pre>
查看以前的工作现场<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git stash list
stash@{0}: WIP on dev: 6224937 add merge</code></pre>
将存储起来的内容恢复（同时从list中删除）<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git stash pop
# On branch dev
# Changes to be committed:
#   (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
#
#       new file:   hello.py
#
# Changes not staged for commit:
#   (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
#   (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)
#
#       modified:   readme.txt
#
Dropped refs/stash@{0} (f624f8e5f082f2df2bed8a4e09c12fd2943bdd40)</code></pre><div>将存储起来的内容恢复（从list中读取，不删除）<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git stash apply stash@{0}</code></pre></div>
将存储起来的内容删除（从list中删除）<br/><div><pre style="font-size: 13px; padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git stash apply drop</code><span style="background-color: transparent; color: inherit; font-size: 12px;">stash@{0}</span></pre></div></li><li>强行删除分支<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git branch -D feature-vulcan</code></pre>
如果要丢弃一个没有被合并过的分支，可以通过git branch -D &lt;name&gt;强行删除。</li><li>查看远程分支的信息<br/><div><pre style="font-size: 13px; padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git remote -v
origin  git@github.com:michaelliao/learngit.git (fetch)
origin  git@github.com:michaelliao/learngit.git (push)</code></pre></div><div>－v 显示更详细的信息</div></li><li>打一个新的标签<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git tag v1.0</code></pre></li><li>查看所有标签<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git tag
v1.0</code></pre></li><li>根据某个提交id ,打新的标签<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git tag v0.9 6224937</code></pre></li><li>查看标签信息<br/><div><pre style="font-size: 13px; padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git show v0.9
commit 622493706ab447b6bb37e4e2a2f276a20fed2ab4
Author: Michael Liao &lt;askxuefeng@gmail.com&gt;
Date:   Thu Aug 22 11:22:08 2013 +0800

    add merge
...</code></pre></div></li><li>创建带说明的标签<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git tag -a v0.1 -m &quot;version 0.1 released&quot; 3628164</code></pre>
-a 标签名<br/>
-m 说明<br/>
还可以通过-s用私钥签名一个标签<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git tag -s v0.2 -m &quot;signed version 0.2 released&quot; fec145</code></pre></li><li>删除标签<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git tag -d v0.1
Deleted tag 'v0.1' (was e078af9)</code></pre></li><li>推送单个标签到远程服务器<br/><div><pre style="font-size: 13px; padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git push origin v1.0
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:michaelliao/learngit.git
 * [new tag]         v1.0 -&gt; v1.0</code></pre></div><div>推送本地所有未推送的标签<br/><div><pre style="font-size: 13px; padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git push origin --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 554 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@github.com:michaelliao/learngit.git
 * [new tag]         v0.2 -&gt; v0.2
 * [new tag]         v0.9 -&gt; v0.9</code></pre></div></div></li><li>删除远程服务器上面的标签<br/>
先从删除本地标签<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git tag -d v0.9
Deleted tag 'v0.9' (was 6224937)</code></pre>
然后删除远程上的标签<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ git push origin :refs/tags/v0.9
To git@github.com:michaelliao/learngit.git
 - [deleted]         v0.9</code></pre><br/></li><li>创建SSH Key，在用户主目录下，看看有没有.ssh目录，如果有，再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件，如果已经有了，可直接跳到下一步。如果没有，打开Shell，创建SSH Key<br/><pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 13px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">$ ssh-keygen -t rsa -C &quot;youremail@example.com&quot;</code></pre>
注意：ssh和后面的&quot;-&quot;之间没有空格。</li><li>https格式<br/><pre style="padding: 9.5px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; word-break: break-all; word-wrap: break-word; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245);"><font face="Monaco, Menlo, Consolas, Courier New, monospace" size="2"><span style="line-height: 20px; white-space: pre-wrap;">https://github.com/pfjhetg/learngit.git</span></font></pre>
git格式
<pre style="padding: 9.5px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 0px; margin-bottom: 10px; line-height: 20px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.148438); background-color: rgb(245, 245, 245); font-size: 13px;"><code style="padding: 0px; font-family: Monaco, Menlo, Consolas, &apos;Courier New&apos;, monospace; font-size: 12px; color: inherit; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; background-color: transparent;">git@github.com:michaelliao/learngit.git</code></pre></li><li>Git本地库和远程库关联时候，需要保证本地主分支要commit进去了一个文件（库不能为空），否者无法提交上去并且提示<br/>
error: src refspec master does not match any.<br/>
error: failed to push some refs to 'git@github.com:pfjhetg/learngit.git'</li><li><b>工作区（Working Directory）</b>：就是你在电脑里能看到的目录，比如我的learngit文件夹就是一个工作区</li><li><b>版本库（Repository）</b>：工作区有一个隐藏目录.git，这个不算工作区，而是Git的版本库</li><li>Git的版本库里存了很多东西，其中最重要的就是称为stage（或者叫index）的暂存区，还有Git为我们自动创建的第一个分支master，以及指向master的一个指针叫HEAD</li><li>git中的当前分支泛指当前所在的分区<br/>
js@JS-PC ~/git/learngit (master)这里的master就是表示在主分区</li><li>从本地推送分支，使用git push origin branch-name，如果推送失败，先用git pull抓取远程的新提交</li><li>在本地创建和远程分支对应的分支，使用git checkout -b branch-name origin/branch-name，本地和远程分支的名称最好一致</li><li>建立本地分支和远程分支的关联，使用git branch --set-upstream branch-name origin/branch-name</li><li>从远程抓取分支，使用git pull，如果有冲突，要先处理冲突<br/><br/></li></ol></div></div>
</div></body></html> 